import request from '@/utils/request'

/**
 * @api {post} /auth/local 用户登录
 * @apiName login
 * @apiGroup 用户
 * @apiVersion 1.0.0
 *
 * @apiParam {String} identifier 用户名或邮箱.
 * @apiParam {String} password 密码.
 *
 * @apiSuccess {String} jwt 用户 Token
 * @apiSuccess {String} user 用户数据对象
 */
export function login(data) {
  return request({
    url: '/auth/local',
    method: 'post',
    data
  })
}

export function register(data) {
  return request({
    url: '/auth/local/register',
    method: 'post',
    data
  })
}

/**
 * @api {get} /users/me 获取当前用户数据
 * @apiName getInfo
 * @apiGroup 用户
 * @apiVersion 1.0.0
 */
export function getInfo(token) {
  return request({
    url: '/users/me',
    method: 'get'
  })
}

export function logout() {
  return request({
    url: '/vue-admin-template/user/logout',
    method: 'post'
  })
}
